package com.ytc.restcontroller;

import com.ytc.mapper.*;
import com.ytc.model.Author;
import com.ytc.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthorServiceImpl {

    @Autowired
    private AuthorMapper authorMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private BooklistMapper booklistMapper;
    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private BookshelfMapper bookshelfMapper;

    //柴晓颖：查询收藏数
    @RequestMapping("queryShelfNum")
    public Long queryShelfNum(@RequestParam("blId") Integer blId){
        return bookshelfMapper.queryShelfNum(blId);
    }

    //柴晓颖：根据id查用户
    @RequestMapping("queryUserById" )
    public User queryUserById(@RequestParam("uId") Integer uId){
        return userMapper.queryUserById(uId);
    }

    //柴晓颖：根据userid查作者
    @RequestMapping("queryAuthoridByUserid")
    public Long queryAuthoridByUserid(@RequestParam("uId") Integer uId){
        return authorMapper.queryAuthoridByUserid(uId);
    }
    /*柴晓颖：新增作者*/
    @RequestMapping("addAuthor")
    public void addAuthor(@RequestBody Author author){
        authorMapper.addAuthor(author);
    }

    //zzm：修改作者
    @RequestMapping("updateAuthor" )
    public void updateAuthor(@RequestBody User user){
        userMapper.updateAuthor(user);
    }

    //张泽萌：通过uid查询作者
    @RequestMapping("queryAuthorByUid")
    public Author queryAuthorByUid(@RequestParam("uId")Integer uId) {
        return authorMapper.queryAuthorByUid(uId);
    }
}
